package com.roc.web.action.estrn;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class BigEstrnHisSearchCondition extends BaseSearchCondition {

	private String minDate;
	private String maxDate;
	private String merchantNo;
	private String range;
	private String etsterMid;
	
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		// TODO Auto-generated method stub
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		if (Constance.isNotEmpty(merchantNo)) {
			filedBeanList.add(new WhereHQLFieldBean("e.MERNO", merchantNo.trim(), "=", false));
		}
		if(Constance.isNotEmpty(minDate)&&Constance.isNotEmpty(maxDate)){
         	filedBeanList.add(new WhereHQLFieldBean("e.etsdate",minDate,">=", false));
       	    filedBeanList.add(new WhereHQLFieldBean("e.etsdate",maxDate,"<=", false));
        }
		if(Constance.isNotEmpty(range)){ //商户号
			if(range.trim().equals("1")){
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",1000000.00,">=",false));
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",2000000.00,"<",false));
			}else if(range.trim().equals("2")){
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",2000000.00,">=",false));
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",3000000.00,"<",false));
			}else if(range.trim().equals("3")){
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",3000000.00,">=",false));
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",4000000.00,"<",false));
			}else if(range.trim().equals("4")){
				filedBeanList.add(new WhereHQLFieldBean("E.AMOUNT",4000000.00,">=",false));	
			}
		}
		
		if(Constance.isNotEmpty(etsterMid)){
			filedBeanList.add(new WhereHQLFieldBean("e.ETSTERMID", etsterMid.trim(), "=", false));
		}
		
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		// TODO Auto-generated method stub
		return "select count(*) "+
				"from ESTRNHISLOG e,ESMIDINFO M "+
		        " where  m.mid=e.merno and e.REVERSAL=0 and e.RESPCODE='00' and e.etstrancode='020000' ";
	}

	@Override
	protected String getSearchHQL() {
		// TODO Auto-generated method stub
	//	return "select  E.ACCOUNT,E.ETSTRANCODE,sum(E.AMOUNT),E.MERNO,E.ETSTERMID,E.ETSDATE " +
		//		"from ESTRNHISLOG e,ESMIDINFO M where e.REVERSAL=0 and e.RESPCODE='00' and m.mid=e.MERNO ";
		/*return "select E.ACCOUNT,E.AMOUNT,E.MERNO,E.ETSTERMID,E.ETSDATE,m.MER_NAME " +
				"from (select  ACCOUNT,sum(E.AMOUNT) amount,MERNO,ETSTERMID,ETSDATE FROM ESTRNHISLOG e where e.REVERSAL=0 and e.RESPCODE='00' group by e.MERNO,e.ETSTERMID,e.account,e.ETSDATE) e,ESMIDINFO M " +
				" where m.mid=e.MERNO ";*/
		return "select E.ACCOUNT,E.AMOUNT,E.MERNO,E.ETSTERMID,E.ETSDATE,m.MER_NAME,m.mcc,m.eng_name,m.eng_br_name "+
				"from ESTRNHISLOG e,ESMIDINFO M "+
		        "where  m.mid=e.merno and e.REVERSAL=0 and e.RESPCODE='00' and e.etstrancode='020000' ";
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return " order by e.etsdate DESC ";
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getMerchantNo() {
		return merchantNo;
	}

	public void setMerchantNo(String merchantNo) {
		this.merchantNo = merchantNo;
	}

	public String getRange() {
		return range;
	}

	public void setRange(String range) {
		this.range = range;
	}

	public String getEtsterMid() {
		return etsterMid;
	}

	public void setEtsterMid(String etsterMid) {
		this.etsterMid = etsterMid;
	}

	
}
